/**
 * @des: 登录验证，不需要则全部注释掉
*/
import store from '@/store/';
import Vue from 'vue';
import { ACCESS_TOKEN } from '@/store/mutation-types';
import router from './router';
const whiteList = ['/user/login', '/user/authlogin', '/404', '/building'];
const loginPath = '/user/login';

router.beforeEach((to, from, next) => {
  if (to.path == '/404') {
    next();
  } else if (Vue.ls.get(ACCESS_TOKEN)) {
    if (to.path === loginPath) {
      next({ path: '/' });
    } else {
      store.dispatch('UserInfo').then(res => {
        // const menuList = store.state.user.menuList;
        // if (!menuList.includes(to.meta.id) && !to.meta.auth) {
        //   next('/404');
        // } else {
        //   next();
        // }
        next();
      }).catch(() => {
        next();
      });
    }
  } else if (whiteList.indexOf(to.path) !== -1) {
    next();
  } else if (to.path == '/detail/index' && to.query.type == 5) {
    next();
  } else {
    next('/user/login');
  }
});
